package com.shengyijie.adapter.view;

import java.util.ArrayList;
import java.util.List;

import com.ant.liao.GifView;
import com.ant.liao.GifView.GifImageType;
import com.shengyijie.activity.R; 
  
import android.app.Activity;
import android.content.Context; 
import android.graphics.drawable.BitmapDrawable; 
import android.os.AsyncTask;
import android.view.Gravity;
import android.view.LayoutInflater; 
import android.view.View;
import android.view.ViewGroup; 
import android.view.ViewGroup.LayoutParams;  
import android.widget.PopupWindow; 
import android.widget.TextView;
import android.widget.PopupWindow.OnDismissListener;

public class AlertBox{

	private Context context;
	private Activity activity;
	private View view; 
	public PopupWindow popupWindow; 
	
    private OnCanceledListener onCanceledListener;
	 
	 public interface OnCanceledListener {
			void onCanceled();
	 }
	 
	 public void setCompletedListener(OnCanceledListener onCanceledListener){
	    	this.onCanceledListener=onCanceledListener;
	 }
	 
	String notice="我正在努力加载中，请稍后...";
	
	private boolean isShow=false;
	 
	  
	public AlertBox(Activity activity,Context context,View view) { 
		this.context = context; 
		this.view=view;
		 
	}
	
	public void setNoticeMessage(String message){
		notice=message;
	}
	 
	 public void show() {
		 try{
			LayoutInflater mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			View menuView = (ViewGroup) mLayoutInflater.inflate(
					R.layout.load, null, true);
			popupWindow = new PopupWindow(menuView, LayoutParams.FILL_PARENT,
						LayoutParams.FILL_PARENT, true); 
			popupWindow.setBackgroundDrawable(new BitmapDrawable());
			TextView tv_notice = (TextView) menuView.findViewById(R.id.notice);
			tv_notice.setText(notice);
			GifView gf = (GifView) menuView.findViewById(R.id.progress);
			gf.setGifImage(R.drawable.loadg);
			gf.setGifImageType(GifImageType.COVER);
			//gf.setShowDimension(300, 300); 
			popupWindow.setOnDismissListener(new OnDismissListener(){
				@Override
				public void onDismiss() { 
					onCanceledListener.onCanceled();
				}});
			popupWindow.setAnimationStyle(R.style.PopupAnimation);
			popupWindow.showAtLocation(view, Gravity.CENTER
					| Gravity.CENTER, 0, 0); 
			popupWindow.update(); 
			 
			isShow=true;
		 }catch(Exception e){
			 String s=e.toString();
		 }
	}
	 
	 public void dismiss() {
		 try{ 
			popupWindow.dismiss(); 
			isShow=false;
		 }catch(Exception e){}
	}

	public boolean isShow() {
		return isShow;
	}

	 
	 
	 
	 
	  
}